package com.example.demo.controller;


import com.example.demo.entity.InstrumentCollection;
import com.example.demo.entity.MusicQuery;
import com.example.demo.entity.NotationCollection;
import com.example.demo.service.InstrumentCollectionService;
import com.example.demo.service.NotationCollectionService;
import com.example.demo.vo.ViewMusicCollectionInfo;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("v1")
public class NotationCollectionController {

    @Autowired
    private NotationCollectionService notationCollectionService;

    // 添加收藏
    @PostMapping("/add")
    public Map<String, Object> addCollection(@RequestBody NotationCollection notationCollection) {
        boolean success = notationCollectionService.addCollection(notationCollection);
        Map<String, Object> response = new HashMap<>();
        response.put("success", success);
        response.put("message", success ? "收藏成功" : "收藏失败");
        return response;
    }

    // 删除收藏
    @DeleteMapping("/delete")
    public Map<String, Object> deleteCollection(@RequestBody NotationCollection notationCollection) {
        boolean success = notationCollectionService.deleteCollection(notationCollection);
        Map<String, Object> response = new HashMap<>();
        response.put("success", success);
        response.put("message", success ? "取消收藏成功" : "取消收藏失败");
        return response;
    }


    // 获取用户的收藏列表
    @GetMapping("/{userId}")
    public List<NotationCollection> getCollectionsByUserId(@PathVariable Integer userId) {
        return notationCollectionService.getCollectionsByUserId(userId);
    }

    // 检查是否收藏
    @GetMapping("/check")
    public Map<String, Object> isCollected(@RequestParam Integer userId, @RequestParam Integer notationId) {
        boolean collected = notationCollectionService.isCollected(userId, notationId);
        Map<String, Object> response = new HashMap<>();
        response.put("collected", collected);
        return response;
    }

    //点击量
    @PostMapping("/notation/View/{notationId}")
    public ResponseEntity<?> ViewNote(@PathVariable Integer notationId) {
        notationCollectionService.incrementViewCount(notationId);
        return ResponseEntity.ok().build();
    }




}
